package 尚硅谷juc大厂.test19;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class Test19 {


    public static ThreadLocal<SimpleDateFormat> threadLocal=ThreadLocal.withInitial(()->new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));

    public static Date parse(String data) throws ParseException {
        return threadLocal.get().parse(data);
    }
    public static  void main(String[] args) throws ParseException {


        for (int i=0;i<5;i++){
            new Thread(()->{
                try {
                    System.out.println(Test19.parse("2021-11-01 12:14:45"));
                } catch (ParseException e) {
                    e.printStackTrace();
                }finally {
                    Test19.threadLocal.remove();
                }
            }).start();
        }
    }
}
